package com.myTest;

import com.alibaba.druid.pool.DruidDataSource;
import com.myTest.annotation.Bean;
import com.myTest.annotation.ComponentScan;
import com.myTest.annotation.Value;

import javax.sql.DataSource;

@ComponentScan({"com.myTest"})//扫描注解路径
public class SpringConfig {
    @Value("${jdbc.driver}")
    private String driverClassName;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Bean("dataSource")
    public DataSource createDataSource(){
        DruidDataSource druidDataSource = new DruidDataSource();
        druidDataSource.setDriverClassName(driverClassName);
        druidDataSource.setUrl(url);
        druidDataSource.setUsername(username);
        druidDataSource.setPassword(password);
        return druidDataSource;
    }
}
